module BaseHelper
  
  def get_page_title
    @normal_action = normal_action
    if @normal_action[params[:controller].to_s].present? && @normal_action[params[:controller].to_s][params[:action].to_sym].present?
      return @normal_action[params[:controller].to_s][params[:action].to_sym]
    else
      # default title
      return "iwebstore"
    end
  end
  
  def normal_action
    {"user" => {},
     "base" => {:index => "iwebstore"}
    }
  end
  
  def will_paginate_remote(paginator, options={})
    update = options.delete(:update)
    url = options.delete(:url)
    with = options.delete(:with)
    #    options[:params].delete(:authenticity_token) if options[:params].present?
    str = will_paginate(paginator, options)
    if str != nil
      str.gsub(/href="(.*?)"/) do
        if with.present?
          "href=\"#\" onclick=\"new Ajax.Updater('" + update.to_s + "', '" + (url ? url + $1.sub(/[^\?]*/, '') : $1) +
         "', {asynchronous:true, evalScripts:true, method:'get', parameters:" + with.to_s + "}); return false;\""
        else
          "href=\"#\" onclick=\"new Ajax.Updater('" + update.to_s + "', '" + (url ? url + $1.sub(/[^\?]*/, '') : $1) +
         "', {asynchronous:true, evalScripts:true, method:'get'}); return false;\""
        end
      end
    end
  end
  
  def format_date(date = "")
    date ? date.strftime("%Y-%m-%H") : ""
  end
  
  def red_star
    "<span><font color='red'>*</font></span>"
  end
  
end
